package com.lv.suyiyong.hfr.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.lv.common.imp.OnPositionTListener
import com.lv.service.bean.GoodsItemBean
import com.lv.service.bean.SpuItemBean
import com.lv.suyiyong.hfr.R
import com.youth.banner.adapter.BannerAdapter

/**
 * 作者： ygx
 * 创建日期：2025/8/8 上午10:24
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * -    _              _           _     _   ____  _             _ _
 * -   / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * -  / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * - / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * -/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 * 描述：首页找厂家的Banner
 */
class BannerHomeBrandAdapter(
    private val list: List<List<GoodsItemBean>>, private val type: Int = 0
) :
    BannerAdapter<List<GoodsItemBean>, BannerHomeBrandAdapter.BannerViewHolder>(list) {

    class BannerViewHolder(item: View) :
        RecyclerView.ViewHolder(item)

    override fun onBindView(
        holder: BannerViewHolder?,
        data: List<GoodsItemBean>?,
        position: Int,
        size: Int
    ) {

        holder ?: return

        //        val tvCpname: TextView = holder.itemView.findViewById(R.id.tv_cpname)
//        val tvAddress: TextView = holder.itemView.findViewById(R.id.tv_address)
        val recyclerView: RecyclerView = holder.itemView.findViewById(R.id.rv_g)
//        tvCpname.text = data?.name
//        tvAddress.text = "${data?.province}${data?.city}"
//        val spuList = data?.spuList
        val mSpuBeans = mutableListOf<GoodsItemBean>()
        data?.let { mSpuBeans.addAll(it) }
        val adapter = BrandBannerAdapter(mSpuBeans, type)
        recyclerView.adapter = adapter
    }

    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
        val mLayout: View =
            LayoutInflater.from(parent!!.context).inflate(R.layout.banner_home_brand, null)

        val clParent: RecyclerView = mLayout.findViewById(R.id.rv_g)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        clParent.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
//        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return BannerViewHolder(mLayout)
    }

    var onViewClickListener: OnPositionTListener<List<GoodsItemBean>>? = null

}